package me.zhengjie.config.entity;

import java.util.List;
import java.util.StringJoiner;

/**
 * 分页查询返回对象
 */
public class CommonPageData<T> {

    public CommonPageData() {
    }

    public CommonPageData(long iTotalRecords, long iTotalDisplayRecords, List<T> data) {
        this.iTotalRecords = iTotalRecords;
        this.iTotalDisplayRecords = iTotalDisplayRecords;
        this.data = data;
        this.totalPage = getTotalPage(iTotalRecords,iTotalDisplayRecords);
    }

    private long iTotalRecords;

    private long iTotalDisplayRecords;

    private long totalPage;

    private List<T> data;

    public long getiTotalRecords() {
        return iTotalRecords;
    }

    public void setiTotalRecords(long iTotalRecords) {
        this.iTotalRecords = iTotalRecords;
    }

    public long getiTotalDisplayRecords() {
        return iTotalDisplayRecords;
    }

    public void setiTotalDisplayRecords(long iTotalDisplayRecords) {
        this.iTotalDisplayRecords = iTotalDisplayRecords;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public long getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(long totalPage) {
        this.totalPage = totalPage;
    }
    //获取总页数
    private long getTotalPage(long total,long pageSize){
        if (total == 0 || pageSize ==0){
            return 0;
        }
        long p = total / pageSize;
        if (total % pageSize == 0){
            return p;
        } else{
            return p + 1;
        }
    }
}
